//
//  LXCarListTableViewCell.m
//  EnterpriseEdition
//
//  Created by ypj on 2021/10/8.
//

#import "LXCarListTableViewCell.h"
#import "CheLiangModel.h"
@implementation LXCarListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.backView1 addCorner:3];
    [self.backView3 addCorner:3];
    [self.carImage addCorner:3];
    [self.carImageV2 addCorner:3];
}


- (void)setCarModel:(CheLiangModel *)carModel{
    _carModel = carModel;
    
    // 图片
    [self.carImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,[NSString isChinese:carModel.car45Url]]] placeholderImage:Image(@"default_icon")];
    // 车牌号码
    self.paiZhaoLb.text = carModel.carNum;
    // 品牌型号
    self.pinPaiLb.text = [NSString stringWithFormat:@"%@%@",carModel.carBrand,carModel.carMode];
    
    
    NSMutableArray *ary = [NSMutableArray array];
    
    
//    // 能源类型
//    if (![[Tool getId:[NSString stringWithFormat:@"%@",@(carModel.energyType)] DicDataWithKey:k_NYLX] isEqualToString:@"-"]) {
//        [ary addObject:[Tool getId:[NSString stringWithFormat:@"%@",@(carModel.energyType)] DicDataWithKey:k_NYLX]];
//    }
//    // 运行平台
//    if (![[Tool getId:carModel.operPlatform DicDataWithKey:k_YXPT] isEqualToString:@"-"]) {
//        [ary addObject:[Tool getId:carModel.operPlatform DicDataWithKey:k_YXPT]];
//    }
//    // 车辆类型
//    if (![[Tool getId:carModel.leaseCarType DicDataWithKey:k_CLLX] isEqualToString:@"-"]) {
//        [ary addObject:[Tool getId:carModel.leaseCarType DicDataWithKey:k_CLLX]];
//    }
    
    
    
//
//    for (UIView *view in self.carTagView.subviews) {
//        [view removeFromSuperview];
//    }
//    CGFloat X = 3;
//    for (int i = 0; i < ary.count; i++) {
//        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(X, 2, 0, 13)];
//        label.text = ary[i];
//        label.textColor = ColorWith3C6CFC;
//        label.backgroundColor = [UIColor colorWithRed:236/255.0 green:240/255.0 blue:253/255.0 alpha:1];
//        label.font = [UIFont systemFontOfSize:10];
//        label.textAlignment = NSTextAlignmentCenter;
//        label.width = [NSString getLabelOptimumWidth:label WithFont:10] + 3;
//        [self.carTagView addSubview:label];
//        X += label.width + 3;
//
//    }
    
    
    NSString *timeDay = [carModel.timeDay intValue]<1?@"1":carModel.timeDay;
    
    self.kongXianLab.text = [NSString stringWithFormat:@"已空置%@天",timeDay];
    [self.kongXianLab addAttributes:TextAttrCorlor([UIColor colorWithHexString:@"#FF921C"]) forString:timeDay size:16];
    self.zuHuLb.textColor = ColorWithAAAAAA;
    self.zuHuLb.text = [NSString stringWithFormat:@"%@年丨%@公里",[NSString stringWithNull:!StringIsEmpty(carModel.registerTime)?[carModel.registerTime substringToIndex:4]:@""],[NSString stringWithNull:carModel.kilometers]];

 
}


- (void)setStockModel:(CheLiangModel *)stockModel{
    _stockModel = stockModel;
    
    // 图片
    [self.carImageV2 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,[NSString isChinese:stockModel.image]]] placeholderImage:Image(@"default_icon")];
    // 车型
    self.carNameLab2.text = [NSString stringWithFormat:@"%@ %@",stockModel.brand, stockModel.model];
  
    
    NSMutableArray *ary = [NSMutableArray array];
    
    
    
    
    // 车辆类型
    if (stockModel.energeType != 1) {
        [ary addObject:@{
            
            @"title":[NSString stringWithFormat:@"续航%@km",stockModel.endurance],
            @"textColor":[UIColor colorWithHexString:@"#FF921C"],
            @"backColor":[[UIColor colorWithHexString:@"#FF921C"] colorWithAlphaComponent:0.1]
        }];
    }
    
    
    // 能源类型
    if (![[Tool getId:[NSString stringWithFormat:@"%@",@(stockModel.energeType)] DicDataWithKey:k_NYLX] isEqualToString:@"-"]) {
        [ary addObject:@{
            @"title":[Tool getId:[NSString stringWithFormat:@"%@",@(stockModel.energeType)] DicDataWithKey:k_NYLX],
            @"textColor":ColorWith3C6CFC,
            @"backColor":[ColorWith3C6CFC colorWithAlphaComponent:0.1]
        }];
    }
    
    // 运行平台
    if (![[Tool getId:stockModel.runPlatfom DicDataWithKey:k_YXPT] isEqualToString:@"-"]) {
        [ary addObject:@{
            @"title":[Tool getId:stockModel.runPlatfom DicDataWithKey:k_YXPT],
            @"textColor":ColorWith3C6CFC,
            @"backColor":[ColorWith3C6CFC colorWithAlphaComponent:0.1]
        }];
         
    }
    // 车辆类型
    if (![[Tool getId:stockModel.carType DicDataWithKey:k_CLLX] isEqualToString:@"-"]) {
        [ary addObject:@{
            @"title":[Tool getId:stockModel.carType DicDataWithKey:k_CLLX],
            @"textColor":ColorWith3C6CFC,
            @"backColor":[ColorWith3C6CFC colorWithAlphaComponent:0.1]
        }];
    }
    
    
    
    
    for (UIView *view in self.carTagView2.subviews) {
        [view removeFromSuperview];
    }
    CGFloat X = 3;
    for (int i = 0; i < ary.count; i++) {
        NSDictionary *dic = ary[i];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(X, 2, 0, 13)];
        label.text = dic[@"title"];
        label.textColor = dic[@"textColor"];
        label.backgroundColor = dic[@"backColor"];
        label.font = [UIFont systemFontOfSize:10];
        label.textAlignment = NSTextAlignmentCenter;
        label.width = [NSString getLabelOptimumWidth:label WithFont:10] + 3;
        [self.carTagView2 addSubview:label];
        X += label.width + 3;
        
    }
    
    
    
    // 出租 type 1 = 出租
    if (stockModel.type == 1){
      
        NSString *price = [NSString stringWithNull:stockModel.floorPrice];
        self.zuHuLb2.text = [NSString stringWithFormat:@"%@元起/月",price];
        [self.zuHuLb2 addAttributes:TextAttrCorlor([UIColor colorWithHexString:@"#FF921C"]) forString:price size:16];
        NSString *stock = [NSString stringWithFormat:@"%@辆",stockModel.carNum];
        self.kuCunLb2.text = [NSString stringWithFormat:@"库存 %@",stock];
        [self.kuCunLb2 addAttributes:TextAttrCorlor([UIColor colorWithHexString:@"#FF921C"]) forString:stock size:10];
        
    }
    else {
        NSString *price = [NSString stringWithNull:stockModel.floorPrice];
        self.zuHuLb2.text = [NSString stringWithFormat:@"%@万元起/首付款",price];
        [self.zuHuLb2 addAttributes:TextAttrCorlor([UIColor colorWithHexString:@"#FF921C"]) forString:price size:16];
        
        NSString *stock = [NSString stringWithFormat:@"%@辆",stockModel.carNum];
        NSString *qi = [NSString stringWithFormat:@"%@期",stockModel.numberInstallments];
        self.kuCunLb2.text = [NSString stringWithFormat:@"可分期 %@ 库存 %@",qi,stock];
        [self.kuCunLb2 addAttributesArray:@[TextAttrCorlor([UIColor colorWithHexString:@"#FF921C"]),TextAttrCorlor([UIColor colorWithHexString:@"#FF921C"])] forStringArray:@[stock,qi] size:10];
    }

    
}
- (void)setRentModel:(CheLiangModel *)rentModel
{
    _rentModel = rentModel;
    /**
     @property (weak, nonatomic) IBOutlet UILabel *label0;
     @property (weak, nonatomic) IBOutlet UILabel *label1;
     @property (weak, nonatomic) IBOutlet UILabel *label2;
     @property (weak, nonatomic) IBOutlet UILabel *label3;
     @property (weak, nonatomic) IBOutlet UILabel *label4;
     */
    NSString *carBrand = [NSString stringWithFormat:@"%@ %@",rentModel.carBrand,rentModel.carMode];
    self.label0.text = [NSString stringWithFormat:@"%@ %@",rentModel.carNum, carBrand];
    [self.label0 addAttributes:TextAttrCorlor(Color333) forString:carBrand size:14];
    
    self.label1.text = [NSString stringWithNull:rentModel.customerName];
    
    if ([rentModel.timeDay intValue] < 0) {
        self.label2.text = [NSString stringWithFormat:@"逾期%@天",@(labs([rentModel.timeDay intValue]))];
        self.label2.textColor = ColorWithEA545A;
    }
    else if([rentModel.timeDay intValue] == 0){
        self.label2.text = @"1天";
        self.label2.textColor = ColorWith333333;
    }
    else {
        self.label2.text = [NSString stringWithFormat:@"%@天",@([rentModel.timeDay intValue])];
        self.label2.textColor = ColorWith333333;
    }
    
    self.label3.text = [NSString toTen:rentModel.rent];
    
    
    if (rentModel.signType == 1 ) {
        self.label4.text = @"租车";
        self.label4.textColor = ColorWith3C6CFC;
        self.label4.backgroundColor = [ColorWith3C6CFC colorWithAlphaComponent:0.1];
    }
    else if (rentModel.signType == 2) {
        self.label4.text = @"购车";
        self.label4.textColor = [UIColor colorWithHexString:@"#ff9214"];
        self.label4.backgroundColor = [[UIColor colorWithHexString:@"#ff9214"] colorWithAlphaComponent:0.1];
    }
    else if(rentModel.signType == 3){
        self.label4.text = @"以租代购";
        self.label4.textColor = ColorWith3C6CFC;
        self.label4.backgroundColor = [ColorWith3C6CFC colorWithAlphaComponent:0.1];
    }
    self.label4Const.constant = [NSString getLabelOptimumWidth:self.label4 WithFont:12] + 3;
    
}

@end
